package com.zzty.txj.serviceImpl;

import com.zzty.txj.dao.DailyMapper;
import com.zzty.txj.entity.Daily;
import com.zzty.txj.entity.User;
import com.zzty.txj.service.DailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class DailyServiceImpl implements DailyService {

    @Autowired
    DailyMapper dailyMapper;

    @Override
    public List<Daily> getDaily() {
        List<Daily>dailies = new ArrayList<>();

   dailies = dailyMapper.getDaily();
        return dailies;
    }

    @Override
    public Integer insertDaily(Daily daily) {
        Integer count = dailyMapper.insertDaily(daily);
        return count;
    }

    @Override
    public Integer deleteDaily(Daily daily) {

        Integer count = dailyMapper.deleteDaily(daily);

        return count;
    }

    @Override
    public String getDailyIdByUserId(Integer userId) {
        String dailyId=dailyMapper.getDailyIdByUserId(userId);
        return dailyId;
    }

    @Override
    public User getUserByOpenId(String openId) {
        User user =new User();
        System.out.println("dailyServiceImpl openId: "+openId);
        user=dailyMapper.getUserByOpenId(openId);
        System.out.println("dailyServiceImpl user: "+user);
        return user;
    }



    @Override
    public Daily getDailyById(Integer id) {
        Daily daily=dailyMapper.getDailyByDailyId(id);
        if(daily!=null){
            return daily;
        }else{
            return null;
        }

    }

}
